#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};
void maxsize(struct TreeNode* root, int* size, int* max)
{
    (*size)++;
    if (root == NULL)
    {
        (*size)--;
        return;
    }
    if (*size > *max)
    {
        *max = *size;
    }
    maxsize(root->left, size, max);
    maxsize(root->right, size, max);
    (*size)--;

}
int maxDepth(struct TreeNode* root) {
    int size = 0;
    int max = 0;
    maxsize(root, &size, &max);
    return max;
}


bool sSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
    {
        return true;
    }
    if ((p && !q) || (!p && q))
    {
        return false;
    }
    if (p->val != q->val)
    {
        return false;
    }
    bool left = sSameTree(p->left, q->left);
    return left != true ? false : sSameTree(p->right, q->right);


}
bool isSameTree(struct TreeNode* p, struct TreeNode* q) {
    if (p == NULL && q == NULL)
        return true;
    if (p == NULL || q == NULL)
        return false;
    if (p->val != q->val)
        return false;
    return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}

bool isUnivalTree(struct TreeNode* root) {
    if (root == NULL)
    {
        return 1;
    }
    if (root->left && root->val != root->left->val
        || root->right && root->val != root->right->val)
    {
        return false;
    }
    bool left = isUnivalTree(root->left);

    return left == false ? false : isUnivalTree(root->right);

}
